package pl.mchaniewski.ryneczek.pojo;

// Generated Oct 3, 2011 3:17:38 AM by Hibernate Tools 3.4.0.CR1

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "indexes", catalog = "stockmarket")
public class Index implements java.io.Serializable {
    private static final long serialVersionUID = -4789707597854580679L;

    private Integer indexid;
    private String name;
    private Set<Company> companies = new HashSet<Company>(0);

    public static final String[] OUT_OF_SYSTEM_INDICES = { "SinglePriceIndex" };

    public Index() {
    }

    public Index(String name) {
        this.name = name;
    }

    public Index(String name, Set<Company> companies) {
        this.name = name;
        this.companies = companies;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "INDEXID", unique = true, nullable = false)
    public Integer getIndexid() {
        return indexid;
    }

    public void setIndexid(Integer indexid) {
        this.indexid = indexid;
    }

    @Column(name = "NAME", nullable = false, length = 30)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "company_index", catalog = "stockmarket", joinColumns = { @JoinColumn(name = "INDEXID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "COMPANYID", nullable = false, updatable = false) })
    public Set<Company> getCompanies() {
        return companies;
    }

    public void setCompanies(Set<Company> companies) {
        this.companies = companies;
    }

    @Transient
    @Override
    public String toString() {
        return getName();
    }

}
